#include "mine.h"

double distribution (double vb)
{
    // Initialize random number generator
    static int flag = 0;
    if (flag == 0) {
	int seed = time (NULL);
	srand (seed);
	flag = 1;
    } 

    // Generate random v vlaue
    double fmax = 0.5 * (1.0 + exp (-2.0 * vb * vb));
    double vmin = -5.0 * vb;
    double vmax = +5.0 * vb;
    double v = vmin + (vmax - vmin) * double(rand ()) / double (RAND_MAX);
    
    // Accept/reject value
    double f = 0.5 * (exp (-(v - vb) * (v - vb) / 2.0) + exp (-(v + vb) * (v + vb) / 2.0));
    double x = fmax * double (rand ()) / double (RAND_MAX);
    if (x > f) return distribution (vb);
    else return v;
}
